package com.getword.web.controller;


import com.getword.domain.City;
import com.getword.service.CityService;
import com.getword.web.model.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/city")
public class ApiCityController {
    @Autowired
    private CityService cityService;
    @Autowired
    private MongoTemplate mongoTemplate;

    @GetMapping
    public Result getCity(Integer level, Integer parentId){
//        Query query = Query.query(Criteria.where("parentId").is(52));
//        mongoTemplate.updateMulti(query, Update.update("parentId", 2), City.class);
        return cityService.getCities(level, parentId);
    }

    @GetMapping("/getCityByArea")
    public Result getCityByArea(Integer areaId){
        return cityService.getCitiesByArea(areaId);
    }

    @GetMapping("/{id}")
    public Result getInfo(@PathVariable Integer id){
        return cityService.getById(id);
    }
}
